package com.npl.demonplservice;

/**
 * Created by frankqian on 2018/7/21.
 */
import edu.stanford.nlp.ling.CoreAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.util.CoreMap;
import edu.stanford.nlp.util.StringUtils;

import java.util.*;

public class Segmentation {
    public static List<String> segInCh(String text) {
        // standard properties
        StanfordCoreNLP pipline = new StanfordCoreNLP("StanfordCoreNLP-chinese.properties");

        Annotation annotation = new Annotation(text);

        pipline.annotate(annotation);

        List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);

        List<String> words = new ArrayList<String>();
        for (CoreMap sentence : sentences) {
            for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) {
                String word = new String(token.getString(CoreAnnotations.TextAnnotation.class));
                words.add(word);
            }
        }
        return words;
    }

}
